<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    <home></home>
  </div>


  <script src="./vue.js"></script>
  <script>
    const Child = {
      template: `
        <div>
          <h3>我是子组件</h3>
          <button @click="biubiubiu">向父组件发送数据</button>
        </div>
      `,
      data(){
        return {
          msg: '我是子组件数据'
        }
      },
      methods: {
        biubiubiu(){ 
          // 触发一个自定义事件 参数1 事件名 参数2是事件触发时携带的参数
          this.$emit('piupiupiu', this.msg)
        }
      }
    }
    const Home = {
      template: `
        <div>
          <h2>我是父组件1</h2>
          {{ msg }}
          <hr/>
          <child @piupiupiu="fn"></child>
        </div>
      `,
      data(){
        return {
          msg: ''
        }
      },
      methods: {
        fn(msg){
          alert('收到了over');
          console.log(msg);
          this.msg = msg;
        }
      },
      components: {
        Child
      }
    }
    Vue.component('Home', Home);
  
    const vm = new Vue({
      el: '#app',
      data: {

      }
    })
  </script>
</body>

</html>